<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改面试</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <h2>修改面试</h2>
        <form id="editForm">
            <input type="hidden" id="id" th:value="${interview.id}">
            <div class="form-group">
                <label>简历</label>
                <select class="form-control" id="resumeId" required>
                    <option th:each="resume : ${resumes}"
                            th:value="${resume.id}"
                            th:text="${resume.user.realName + ' - ' + resume.job.title}"
                            th:selected="${resume.id == interview.resume.id}">
                    </option>
                </select>
            </div>
            <div class="form-group">
                <label>面试时间</label>
                <input type="datetime-local" class="form-control" id="interviewTime" th:value="${#temporals.format(interview.interviewTime, 'yyyy-MM-dd''T''HH:mm')}" required>
            </div>
            <div class="form-group">
                <label>面试地点</label>
                <input type="text" class="form-control" id="location" th:value="${interview.location}" required>
            </div>
            <div class="form-group">
                <label>面试官</label>
                <input type="text" class="form-control" id="interviewer" th:value="${interview.interviewer}" required>
            </div>
            <div class="form-group">
                <label>面试类型</label>
                <select class="form-control" id="type" required>
                    <option value="初试" th:selected="${interview.type == '初试'}">初试</option>
                    <option value="复试" th:selected="${interview.type == '复试'}">复试</option>
                    <option value="终试" th:selected="${interview.type == '终试'}">终试</option>
                </select>
            </div>
            <div class="form-group">
                <label>面试状态</label>
                <select class="form-control" id="status" required>
                    <option value="待面试" th:selected="${interview.status == '待面试'}">待面试</option>
                    <option value="已面试" th:selected="${interview.status == '已面试'}">已面试</option>
                    <option value="已通过" th:selected="${interview.status == '已通过'}">已通过</option>
                    <option value="未通过" th:selected="${interview.status == '未通过'}">未通过</option>
                </select>
            </div>
            <div class="form-group">
                <label>面试反馈</label>
                <textarea class="form-control" id="feedback" rows="3" th:text="${interview.feedback}"></textarea>
            </div>
            <button type="submit" class="btn btn-primary">保存</button>
            <a href="/interview/list" class="btn btn-secondary">返回</a>
        </form>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        document.getElementById('editForm').onsubmit = function(e) {
            e.preventDefault();
            const data = {
                id: document.getElementById('id').value,
                resumeId: document.getElementById('resumeId').value,
                interviewTime: document.getElementById('interviewTime').value,
                location: document.getElementById('location').value,
                interviewer: document.getElementById('interviewer').value,
                type: document.getElementById('type').value,
                status: document.getElementById('status').value,
                feedback: document.getElementById('feedback').value
            };
            axios.post('/interview/update', data)
                .then(response => {
                    alert('修改成功');
                    location.href = '/interview/list';
                })
                .catch(error => {
                    alert('修改失败');
                });
        };
    </script>
</body>
</html> 